//
//  AgreementView.m
//  OnionHome
//
//  Created by fengjie on 2019/10/24.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AgreementView.h"


@interface AgreementView ()
/**<#属性#>*/
@property (nonatomic,strong)UIButton*selecteBtn;
@end

@implementation AgreementView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{

    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    
    [self addSubview:self.selecteBtn];
    
    [self addSubview:label];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"我已阅读并同意《用户服务协议及隐私政策》"attributes: @{NSFontAttributeName: SYSTEMFONT(12),NSForegroundColorAttributeName: [UIColor colorWithRed:149/255.0 green:158/255.0 blue:151/255.0 alpha:1.0]}];
    
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:149/255.0 green:158/255.0 blue:151/255.0 alpha:1.000000]} range:NSMakeRange(0, 7)];
    
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:149/255.0 green:158/255.0 blue:151/255.0 alpha:1.000000]} range:NSMakeRange(7, 13)];
    
    label.attributedText = string;
    label.textAlignment = NSTextAlignmentLeft;
    label.alpha = 1.0;
    
    
    [self.selecteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(15);
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(label);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selecteBtn.mas_right).offset(10);
        make.right.mas_equalTo(0);
        make.top.bottom.mas_equalTo(0);
    }];
}

-(UIButton*)selecteBtn{
    if(!_selecteBtn){
        _selecteBtn=[UIButton new];
        [_selecteBtn setImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
        [_selecteBtn setImage:IMAGE_NAMED(@"delete_check_selecet") forState:UIControlStateSelected];
        kWeakSelf(weakSelf);
        [_selecteBtn addActionHandler:^{
            weakSelf.selecteBtn.selected = !weakSelf.selecteBtn.selected;
            weakSelf.isSelected = weakSelf.selecteBtn.selected;
            BlockSafeRun(weakSelf.touchHandler);
        }];
    }
    return _selecteBtn;
}
@end
